package m;

import java.io.*;
import java.util.*;

public class Command {

  public void shutdown() {
    exec("shutdown -s -t 30");
  }

  public void cancel(){
    exec("shutdown -a");
  }

  private void exec(String command){
    try {
      String line;
      Process p = Runtime.getRuntime().exec(command);
      BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader bre = new BufferedReader
        (new InputStreamReader(p.getErrorStream()));
      while ((line = bri.readLine()) != null) {
        System.out.println(line);
      }
      bri.close();
      while ((line = bre.readLine()) != null) {
        System.out.println(line);
      }
      bre.close();
      p.waitFor();
      System.out.println("Done.");
    }
    catch (Exception err) {
      err.printStackTrace();
    }
  }
} 
